# orders/urls.py
from . import views
from django.urls import path, include
from rest_framework.routers import DefaultRouter
from .views import wechat_pay_notify
#app_name = 'orders'

router = DefaultRouter()
#router.register(r'admin/orders', views.AdminOrderListView, basename='admin-order')

urlpatterns = [
    # 消费端订单API
    path('', views.OrderListView.as_view(), name='order-list'),
    path('create/', views.OrderCreateView.as_view(), name='order-create'),
    path('<int:pk>/', views.OrderDetailView.as_view(), name='order-detail'),
    path('<int:pk>/status/', views.OrderStatusUpdateView.as_view(), name='order-status-update'),
    path('<int:order_id>/status-logs/', views.OrderStatusLogView.as_view(), name='order-status-logs'),
    path('<int:pk>/cancel/', views.OrderCancelView.as_view(), name='order-cancel'),
    path('<int:pk>/pay/', views.OrderPayView.as_view(), name='order-pay'),
    path('pay/notify/', views.wechat_pay_notify, name='wechat_pay_notify'),
    path('wechat-pay-notify/', wechat_pay_notify, name='wechat-pay-notify'),
    # 用户相关订单
    path('user/orders/', views.UserOrderListView.as_view(), name='user-order-list'),
    path('user/orders/<int:pk>/', views.OrderDetailView.as_view(), name='user-order-detail'),
    
    # 厨师端订单API
    path('chef/orders/', views.ChefOrderListView.as_view(), name='chef-order-list'),
    path('chef/orders/<int:pk>/', views.ChefOrderDetailView.as_view(), name='chef-order-detail'),
    path('chef/orders/<int:pk>/accept/', views.ChefOrderAcceptView.as_view(), name='chef-order-accept'),
    path('chef/orders/<int:pk>/reject/', views.ChefOrderRejectView.as_view(), name='chef-order-reject'),
    path('chef/orders/<int:pk>/start/', views.ChefOrderStartView.as_view(), name='chef-order-start'),
    path('chef/orders/<int:pk>/complete/', views.ChefOrderCompleteView.as_view(), name='chef-order-complete'),
    
    # 后台管理API (使用ViewSet)
    #path('', include(router.urls)),
    
    # 厨师服务端API
    path('chef-service/orders/', views.ChefServiceOrderViewSet.as_view({'get': 'list'}), name='chef-service-order-list'),
    path('chef-service/orders/<int:pk>/', views.ChefServiceOrderViewSet.as_view({
        'get': 'retrieve',
        'put': 'update',
        'patch': 'partial_update'
    }), name='chef-service-order-detail'),
    path('chef-service/orders/<int:pk>/status/', views.ChefServiceOrderStatusView.as_view(), name='chef-service-order-status'),


]

# 订单状态机状态定义
ORDER_STATUS_CHOICES = [
    ('pending', '待支付'),
    ('paid', '已支付'),
    ('confirmed', '已确认'),
    ('preparing', '准备中'),
    ('cooking', '烹饪中'),
    ('ready', '已就绪'),
    ('delivering', '配送中'),
    ('completed', '已完成'),
    ('cancelled', '已取消'),
    ('refunded', '已退款')
]